/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 */

package com.xci.edu.core.api;

import com.github.lvyanyang.annotation.Authorize;
import com.github.lvyanyang.core.BaseController;
import com.github.lvyanyang.core.BoolResult;
import com.github.lvyanyang.core.Const;
import com.github.lvyanyang.core.PageList;
import com.github.lvyanyang.core.XCI;
import com.xci.edu.core.entity.ExamPre;
import com.xci.edu.core.entity.ExamPreExtend;
import com.xci.edu.core.filter.ExamPreFilter;
import com.xci.edu.core.service.ExamPreService;
import com.github.lvyanyang.model.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 考试预约接口
 * @author 马星俊 maxingjun@xci96716.com
 * @since 2020-11-24 18:00:15
 */
@Api(tags = "考试预约接口")
@Authorize
@RestController
@RequestMapping(value = "/api/core/examPre", produces = Const.PROJSON)
public class ExamPreApiController extends BaseController {
    /** 考试预约服务 */
    @Resource private ExamPreService examPreService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新建考试预约")
    //@Authorize(code = "core.examPre.insert")
    @PostMapping("/insert")
    public BoolResult insert(@RequestBody ExamPre entity) {
        return examPreService.insert(entity);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "修改考试预约")
    //@Authorize(code = "core.examPre.update")
    @PostMapping("/update")
    public BoolResult update(@RequestBody ExamPre entity) {
        return examPreService.update(entity);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "修改考试预约状态")
    //@Authorize(code = "core.examPre.updateStatus")
    @PostMapping(value = "/updateStatus")
    public BoolResult updateStatus(@RequestBody IdsStatusBody body) {
        examPreService.updateStatus(body.getIds(), body.getStatus());
        return BoolResult.success();
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主键字符串删除考试预约")
    //@Authorize(code = "core.examPre.delete")
    @PostMapping(value = "/delete")
    public BoolResult delete(@RequestBody IdsBody body) {
        return examPreService.delete(body.getIds());
    }

    //@ApiOperationSupport(order = 4)
    //@ApiOperation(value = "检查考试预约主键是否存在")
    //@PostMapping(value = "/existById")
    //public BoolResult existById(@RequestBody IdBody body) {
    //    return BoolResult.success(examPreService.existById(body.getId()));
    //}
    //@ApiOperationSupport(order = 5)
    //@ApiOperation(value = "检查考试预约名称是否存在")
    //@PostMapping(value = "/existByName")
    //public BoolResult existByName(@RequestBody NameExcludeIdBody body) {
    //    return BoolResult.success(examPreService.existByName(body.getName(), body.getExcludeId()));
    //}
    //@ApiOperationSupport(order = 6)
    //@ApiOperation(value = "检查考试预约编码是否存在")
    //@PostMapping(value = "/existByCode")
    //public BoolResult existByCode(@RequestBody CodeExcludeIdBody body) {
    //    return BoolResult.success(examPreService.existByCode(body.getCode(), body.getExcludeId()));
    //}

    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "根据主键查询单个考试预约")
    //@Authorize(code = "core.examPre.select")
    @PostMapping("/selectById")
    public BoolResult<ExamPre> selectById(@RequestBody IdBody body) {
        return BoolResult.success(examPreService.selectById(body.getId()));
    }

    //@ApiOperationSupport(order = 8)
    //@ApiOperation(value = "根据编码查询单个考试预约")
    ////@Authorize(code = "core.examPre.select")
    //@PostMapping("/selectByCode")
    //public BoolResult<ExamPre> selectByCode(@RequestBody CodeBody body) {
    //    return BoolResult.success(examPreService.selectByCode(body.getCode()));
    //}

    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "查询考试预约分页列表")
    //@Authorize(code = "core.examPre.select")
    @PostMapping("/selectPageList")
    public BoolResult<PageList<ExamPreExtend>> selectPageList(@RequestBody ExamPreFilter filter) {
        return BoolResult.success(examPreService.selectPageList(filter));
    }

    @ApiOperationSupport(order = 10, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    @ApiOperation(value = "查询考试预约列表")
    //@Authorize(code = "core.examPre.select")
    @PostMapping("/selectList")
    public BoolResult<List<ExamPreExtend>> selectList(@RequestBody ExamPreFilter filter) {
        return BoolResult.success(examPreService.selectList(filter));
    }

    @ApiOperationSupport(order = 11, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    @ApiOperation(value = "导出考试预约列表")
    //@Authorize(code = "core.examPre.export")
    @PostMapping(value = "/export", produces = {Const.PROOCTET, Const.PROJSON})
    public void export(@RequestBody ExamPreFilter filter) {
        XCI.exportExcel(examPreService.selectList(filter), ExamPre.class, "考试预约列表");
    }

    //@ApiOperationSupport(order = 12)
    //@ApiOperation(value = "获取考试预约导出字段")
    //@PostMapping(value = "/exportNames")
    //public BoolResult<List<String>> exportNames() {
    //    return BoolResult.success(XCI.getExcelFiledNames(ExamPre.class));
    //}
}